/**
 * 
 */
package mt.client.GUI;

import static org.junit.Assert.*;

import java.util.ArrayList;

import mt.Order;
import mt.client.StockResume;
import mt.dummy.ClientCommDummy;

import org.junit.Test;

/**
 * @author Paulo
 *
 */
public class ClientGUITest {

	/**
	 * Test method for {@link mt.client.GUI.ClientGUI#placeOrder(java.lang.String, mt.client.StockResume)}.
	 */
	@Test
	public void testPlaceOrder() {
		
			ClientGUI frame = new ClientGUI();

			ClientCommDummy clientCommDummy = new ClientCommDummy(
					"localhost", "es-2014-group54");

			frame.start(clientCommDummy);

			frame.setVisible(false);
			
			ArrayList<Order> orders = new ArrayList<Order>();
			ArrayList<StockResume> stockResumes = new ArrayList<StockResume>(); 
			Order sellOrder1 = Order.createSellOrder("Person4", "EDP", 10, 100.00);
			Order sellOrder4 =Order.createSellOrder("Person1", "EDP", 10, 400.00);
			orders.add(sellOrder1);
			orders.add(sellOrder4);
			StockResume stockResume = new StockResume.SellOrdersResume("EDP");
			stockResume.addOrder(sellOrder1);
			stockResume.addOrder(sellOrder4);
			stockResumes.add(stockResume);
			frame.setStockResume(orders, stockResumes);
			String quantity = "9";
			frame.placeOrder(quantity, stockResume);
		    quantity = "0";
			frame.placeOrder(quantity, stockResume);
			frame.placeOrder(quantity, null);
			quantity = "30";
			frame.placeOrder(quantity, stockResume);
			quantity = " ";
			frame.placeOrder(quantity, stockResume);
			quantity = "20";
			frame.placeOrder(quantity, stockResume);
			quantity = "-1";
			frame.placeOrder(quantity, stockResume);

			Order sellOrder5 = Order.createSellOrder("Person7", "EPAL", 10, 100.00);
			StockResume stockResume2 = new StockResume.SellOrdersResume("EPAL");
			stockResume2.setBuyOrder(true);
			stockResume2.addOrder(sellOrder5);
			frame.placeOrder("5", stockResume2);
			frame.placeOrder("5", stockResume2);
			
			Order sellOrder6 = Order.createSellOrder("Person7", "EPAL1", 10, 100.00);
			StockResume stockResume3 = new StockResume.SellOrdersResume("EPAL1");
			stockResume2.setBuyOrder(true);
			stockResume2.addOrder(sellOrder6);
			frame.placeOrder("30", stockResume3);
			

	}

	/**
	 * Test method for {@link mt.client.GUI.ClientGUI#selectOrder(mt.client.StockResume)}.
	 */
	@Test
	public void testSelectOrder() {
		ClientGUI frame = new ClientGUI();

		ClientCommDummy clientCommDummy = new ClientCommDummy(
				"localhost", "es-2014-group54");

		frame.start(clientCommDummy);

		frame.setVisible(false);
		
		ArrayList<Order> orders = new ArrayList<Order>();
		ArrayList<StockResume> stockResumes = new ArrayList<StockResume>(); 
		Order sellOrder1 = Order.createSellOrder("Person4", "EDP", 10, 100.00);
		Order sellOrder4 =Order.createSellOrder("Person1", "EDP", 10, 400.00);
		Order sellOrder3 =Order.createSellOrder("Person6", "BRISA", 10, 300.00);
        Order buyOrder1 = Order.createBuyOrder("Person8", "EDP", 10, 100.00);        
        Order buyOrder2 =Order.createBuyOrder("Person7", "GALP", 10, 200.00);
        Order buyOrder3 =Order.createBuyOrder("Person6", "BRISA", 10, 300.00);
        Order buyOrder4 =Order.createBuyOrder("Person5", "EDP", 10, 400.00);
		orders.add(sellOrder1);
		orders.add(sellOrder4);
		orders.add(sellOrder3);
		orders.add(buyOrder4);
		orders.add(buyOrder3);
		orders.add(buyOrder2);
		orders.add(buyOrder1);
		StockResume stockResume = new StockResume.SellOrdersResume("EDP");
		stockResume.addOrder(sellOrder1);
		stockResume.addOrder(sellOrder4);
		stockResumes.add(stockResume);
		frame.selectOrder(stockResume);

		StockResume stockResumeBuy = new StockResume.BuyOrdersResume("EDP");
		stockResumeBuy.setBuyOrder(true);
		stockResume.addOrder(buyOrder1);
		stockResume.addOrder(buyOrder4);
		stockResumes.add(stockResumeBuy);
		frame.selectOrder(stockResumeBuy);

		
	}
	
	

	
	 /* Test method for {@link mt.client.GUI.ClientGUI#setStockResume(java.util.ArrayList, java.util.ArrayList)}.
	*/ 
	@Test
	public void testSetStockResume() {
		ClientGUI frame = new ClientGUI();

		ClientCommDummy clientCommDummy = new ClientCommDummy(
				"localhost", "es-2014-group54");

		frame.start(clientCommDummy);

		frame.setVisible(false);
		
		ArrayList<Order> orders = new ArrayList<Order>();
		ArrayList<StockResume> stockResumes = new ArrayList<StockResume>(); 
		Order sellOrder1 = Order.createSellOrder("Person4", "EDP", 10, 100.00);
		Order sellOrder4 =Order.createSellOrder("Person1", "EDP", 10, 400.00);
		Order sellOrder3 =Order.createSellOrder("Person6", "BRISA", 10, 300.00);
		Order sellOrder5 = Order.createSellOrder("P14", "PT", 10, 100.00);
        Order buyOrder1 = Order.createBuyOrder("Person8", "EDP", 10, 100.00);        
        Order buyOrder2 =Order.createBuyOrder("Person7", "GALP", 10, 200.00);
        Order buyOrder3 =Order.createBuyOrder("Person6", "BRISA", 10, 300.00);
        Order buyOrder4 =Order.createBuyOrder("Person5", "EDP", 10, 400.00);
		orders.add(buyOrder4);
		orders.add(buyOrder3);
		orders.add(buyOrder2);
		orders.add(buyOrder1);
		orders.add(sellOrder1);
		orders.add(sellOrder4);
		orders.add(sellOrder3);
		orders.add(sellOrder5);
		StockResume stockResume = new StockResume.SellOrdersResume("EDP");
		stockResume.addOrder(sellOrder1);
		stockResume.addOrder(sellOrder4);
	

		StockResume stockResumeBuy = new StockResume.BuyOrdersResume("EDP");
		stockResumeBuy.addOrder(buyOrder1);
		stockResumeBuy.addOrder(buyOrder4);
		stockResumeBuy.addOrder(buyOrder3);
		stockResumeBuy.addOrder(buyOrder2);
		stockResume.addOrder(sellOrder3);
		stockResumes.add(stockResume);	
		stockResumes.add(stockResumeBuy);
		frame.setStockResume(orders, stockResumes);
		stockResumes.clear();	
		frame.setStockResume(orders, stockResumes);
		orders.clear();
		orders.add(sellOrder1);
		orders.add(sellOrder4);
		orders.add(sellOrder3);
		orders.add(buyOrder4);
		orders.add(buyOrder3);
		orders.add(buyOrder2);
		orders.add(buyOrder1);
		frame.setStockResume(orders, stockResumes);

	}


}
